Page({
    data: {
        nameName: '',
        businessList: [],  //初始数据
        page_size: 10,   //每页大小
        page_num: 1,     //第几页
        totalPage: '',   //总页数
        searchLoading: false,  //"上拉加载"的变量，默认false，隐藏
    },

    onLoad(){
      this.dataList()
    },
//数据初始化
dataList(){
    wx.request({
      url: 'http://a1.iwmls.com/index/shangji/index',
      method: 'GET',
      data: {
        page_size: this.data.page_size,
        page_num: this.data.page_num
      },
      success: (res) => {
        this.setData({
          businessList: [...this.data.businessList, ...res.data.data],
          totalpage: res.data.page
        })
        
      }
    })
},
//搜索
searchTitle: function(e){
  console.log(e)
  wx.request({
    url: 'http://a1.iwmls.com/index/shangji/search',
    method: 'POST',
    data: {
      title: e.detail.value
    },
    success: (res) => {
      console.log(res)
      this.setData({
        businessList: res.data.data
      })
    }
  })
},
  //点击跳转详情页
handleNavigate(e) {
  const id = e.currentTarget.dataset.id
  console.log(id)
    wx.navigateTo({
      url: `/pages/cat/cat?id=${id}`,
      success: function() {
        console.log('跳转成功')
      },
      fail: function() {
        console.log('跳转失败')
      }
    })
  },

  
    // 搜索输入处理
    onSearchInput(e) {
      const keyword = e.detail.value
      // TODO: 实现搜索逻辑
    },
  
    // 上拉刷新
    onPullDownRefresh() {
      this.setData({
        page_num: 1,
        businessList: ''
      })
      this.dataList()
      wx.showToast({ 
        title: '已经是最新消息了~' ,
      })
      wx.stopPullDownRefresh()
     
      
      
    },
    //跳转发布页
    goTo(){
      wx.navigateTo({
        url: '/pages/release/release',
      })
    },
    // 触底加载更多
    onReachBottom() {
      this.setData({
        searchLoading: true,  //显示正在加载
      })
      this.data.page_num ++ 
      if(this.data.totalpage < this.data.page_num){
        setTimeout(() => {
          this.setData({
            searchLoading: false
          })
          wx.showToast({
            title: '我也是有底线的~',
            icon: 'none'
          })
        }, 1000);
        return
      }
      setTimeout(() => {
        this.dataList()
      }, 1000);
    }
  })